{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "axFEEzo3gm81"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "scrolled": false,
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 369
        },
        "id": "6inhzPCagm84",
        "outputId": "aaba0bfd-3989-418c-d254-f5d5a4bdbf90"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   Car ID  Symboling                  Car Name Fuel Type Aspiration  \\\n",
              "0       1          3        alfa-romero giulia       gas        std   \n",
              "1       2          3       alfa-romero stelvio       gas        std   \n",
              "2       3          1  alfa-romero Quadrifoglio       gas        std   \n",
              "3       4          2               audi 100 ls       gas        std   \n",
              "4       5          2                audi 100ls       gas        std   \n",
              "\n",
              "  Door Number     Car Body Drive Wheel Engine Location  Wheel Base  ...  \\\n",
              "0         two  convertible         rwd           front        88.6  ...   \n",
              "1         two  convertible         rwd           front        88.6  ...   \n",
              "2         two    hatchback         rwd           front        94.5  ...   \n",
              "3        four        sedan         fwd           front        99.8  ...   \n",
              "4        four        sedan         4wd           front        99.4  ...   \n",
              "\n",
              "   Engine Size  Fuel System  Bore Ratio  Stroke Compression Ratio Horse Power  \\\n",
              "0          130         mpfi        3.47    2.68               9.0         111   \n",
              "1          130         mpfi        3.47    2.68               9.0         111   \n",
              "2          152         mpfi        2.68    3.47               9.0         154   \n",
              "3          109         mpfi        3.19    3.40              10.0         102   \n",
              "4          136         mpfi        3.19    3.40               8.0         115   \n",
              "\n",
              "   Peak RPM City MPG  Highway MPG  Price  \n",
              "0        5K       21           27  13495  \n",
              "1        5K       21           27  16500  \n",
              "2        5K       19           26  16500  \n",
              "3      5500       24           30  13950  \n",
              "4      5500       18           22  17450  \n",
              "\n",
              "[5 rows x 26 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-00c304fb-06a8-4e43-b405-a6a57f23caf8\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Car ID</th>\n",
              "      <th>Symboling</th>\n",
              "      <th>Car Name</th>\n",
              "      <th>Fuel Type</th>\n",
              "      <th>Aspiration</th>\n",
              "      <th>Door Number</th>\n",
              "      <th>Car Body</th>\n",
              "      <th>Drive Wheel</th>\n",
              "      <th>Engine Location</th>\n",
              "      <th>Wheel Base</th>\n",
              "      <th>...</th>\n",
              "      <th>Engine Size</th>\n",
              "      <th>Fuel System</th>\n",
              "      <th>Bore Ratio</th>\n",
              "      <th>Stroke</th>\n",
              "      <th>Compression Ratio</th>\n",
              "      <th>Horse Power</th>\n",
              "      <th>Peak RPM</th>\n",
              "      <th>City MPG</th>\n",
              "      <th>Highway MPG</th>\n",
              "      <th>Price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero giulia</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>13495</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero stelvio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>alfa-romero Quadrifoglio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>hatchback</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>94.5</td>\n",
              "      <td>...</td>\n",
              "      <td>152</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>5K</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100 ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>four</td>\n",
              "      <td>sedan</td>\n",
              "      <td>fwd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.8</td>\n",
              "      <td>...</td>\n",
              "      <td>109</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>5500</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "      <td>13950</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>four</td>\n",
              "      <td>sedan</td>\n",
              "      <td>4wd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.4</td>\n",
              "      <td>...</td>\n",
              "      <td>136</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>5500</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "      <td>17450</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 26 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-00c304fb-06a8-4e43-b405-a6a57f23caf8')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-00c304fb-06a8-4e43-b405-a6a57f23caf8 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-00c304fb-06a8-4e43-b405-a6a57f23caf8');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 2
        }
      ],
      "source": [
        "df = pd.read_csv('car_data.csv')\n",
        "\n",
        "df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "6a0o_38kgm86",
        "outputId": "65f7cc95-f0ad-4197-ec3f-36491f61c9bf"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Index(['Car ID', 'Symboling', 'Car Name', 'Fuel Type', 'Aspiration',\n",
              "       'Door Number', 'Car Body', 'Drive Wheel', 'Engine Location',\n",
              "       'Wheel Base', 'Car Length', 'Car Width', 'Car Height', 'Curb Weight',\n",
              "       'Engine Type', 'Cylinder Number', 'Engine Size', 'Fuel System',\n",
              "       'Bore Ratio', 'Stroke', 'Compression Ratio', 'Horse Power', 'Peak RPM',\n",
              "       'City MPG', 'Highway MPG', 'Price'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {},
          "execution_count": 3
        }
      ],
      "source": [
        "df.columns"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Issues with the dataframe?\n",
        "# Column Names\n",
        "# In this case study we will focus on Car Name, Door Number and Peak RPM."
      ],
      "metadata": {
        "id": "dG-tcu75gxBm"
      },
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "W2ud7uxzgm87",
        "outputId": "f30574a0-fc19-497b-9601-d51c8d800fbd"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 205 entries, 0 to 204\n",
            "Data columns (total 26 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   Car ID             205 non-null    int64  \n",
            " 1   Symboling          205 non-null    int64  \n",
            " 2   Car Name           205 non-null    object \n",
            " 3   Fuel Type          205 non-null    object \n",
            " 4   Aspiration         205 non-null    object \n",
            " 5   Door Number        205 non-null    object \n",
            " 6   Car Body           205 non-null    object \n",
            " 7   Drive Wheel        205 non-null    object \n",
            " 8   Engine Location    205 non-null    object \n",
            " 9   Wheel Base         205 non-null    float64\n",
            " 10  Car Length         205 non-null    float64\n",
            " 11  Car Width          205 non-null    float64\n",
            " 12  Car Height         205 non-null    float64\n",
            " 13  Curb Weight        205 non-null    int64  \n",
            " 14  Engine Type        205 non-null    object \n",
            " 15  Cylinder Number    205 non-null    object \n",
            " 16  Engine Size        205 non-null    int64  \n",
            " 17  Fuel System        205 non-null    object \n",
            " 18  Bore Ratio         205 non-null    float64\n",
            " 19  Stroke             205 non-null    float64\n",
            " 20  Compression Ratio  205 non-null    float64\n",
            " 21  Horse Power        205 non-null    int64  \n",
            " 22  Peak RPM           205 non-null    object \n",
            " 23  City MPG           205 non-null    int64  \n",
            " 24  Highway MPG        205 non-null    int64  \n",
            " 25  Price              205 non-null    object \n",
            "dtypes: float64(7), int64(7), object(12)\n",
            "memory usage: 41.8+ KB\n"
          ]
        }
      ],
      "source": [
        "df.info()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OsIifTYMgm88"
      },
      "source": [
        "### Fixing Column Names"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "DjhNLy5Sgm8_",
        "outputId": "68d0992b-730d-4569-a38b-83ec654d1b57"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['car_id',\n",
              " 'symboling',\n",
              " 'car_name',\n",
              " 'fuel_type',\n",
              " 'aspiration',\n",
              " 'door_number',\n",
              " 'car_body',\n",
              " 'drive_wheel',\n",
              " 'engine_location',\n",
              " 'wheel_base',\n",
              " 'car_length',\n",
              " 'car_width',\n",
              " 'car_height',\n",
              " 'curb_weight',\n",
              " 'engine_type',\n",
              " 'cylinder_number',\n",
              " 'engine_size',\n",
              " 'fuel_system',\n",
              " 'bore_ratio',\n",
              " 'stroke',\n",
              " 'compression_ratio',\n",
              " 'horse_power',\n",
              " 'peak_rpm',\n",
              " 'city_mpg',\n",
              " 'highway_mpg',\n",
              " 'price']"
            ]
          },
          "metadata": {},
          "execution_count": 6
        }
      ],
      "source": [
        "col_names = [ col.lower().replace(' ', '_') for col in df.columns ]\n",
        "\n",
        "col_names"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {
        "id": "JGXJMMUBgm9A"
      },
      "outputs": [],
      "source": [
        "df.columns = col_names"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 352
        },
        "id": "JAsR1wE8gm9C",
        "outputId": "ec0b36f9-f2a4-446b-c126-6b573d860b4b"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   car_id  symboling                  car_name fuel_type aspiration  \\\n",
              "0       1          3        alfa-romero giulia       gas        std   \n",
              "1       2          3       alfa-romero stelvio       gas        std   \n",
              "2       3          1  alfa-romero Quadrifoglio       gas        std   \n",
              "3       4          2               audi 100 ls       gas        std   \n",
              "4       5          2                audi 100ls       gas        std   \n",
              "\n",
              "  door_number     car_body drive_wheel engine_location  wheel_base  ...  \\\n",
              "0         two  convertible         rwd           front        88.6  ...   \n",
              "1         two  convertible         rwd           front        88.6  ...   \n",
              "2         two    hatchback         rwd           front        94.5  ...   \n",
              "3        four        sedan         fwd           front        99.8  ...   \n",
              "4        four        sedan         4wd           front        99.4  ...   \n",
              "\n",
              "   engine_size  fuel_system  bore_ratio  stroke compression_ratio horse_power  \\\n",
              "0          130         mpfi        3.47    2.68               9.0         111   \n",
              "1          130         mpfi        3.47    2.68               9.0         111   \n",
              "2          152         mpfi        2.68    3.47               9.0         154   \n",
              "3          109         mpfi        3.19    3.40              10.0         102   \n",
              "4          136         mpfi        3.19    3.40               8.0         115   \n",
              "\n",
              "   peak_rpm city_mpg  highway_mpg  price  \n",
              "0        5K       21           27  13495  \n",
              "1        5K       21           27  16500  \n",
              "2        5K       19           26  16500  \n",
              "3      5500       24           30  13950  \n",
              "4      5500       18           22  17450  \n",
              "\n",
              "[5 rows x 26 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-c00d0d19-9e22-4cfb-b577-96f5148d65b3\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>car_id</th>\n",
              "      <th>symboling</th>\n",
              "      <th>car_name</th>\n",
              "      <th>fuel_type</th>\n",
              "      <th>aspiration</th>\n",
              "      <th>door_number</th>\n",
              "      <th>car_body</th>\n",
              "      <th>drive_wheel</th>\n",
              "      <th>engine_location</th>\n",
              "      <th>wheel_base</th>\n",
              "      <th>...</th>\n",
              "      <th>engine_size</th>\n",
              "      <th>fuel_system</th>\n",
              "      <th>bore_ratio</th>\n",
              "      <th>stroke</th>\n",
              "      <th>compression_ratio</th>\n",
              "      <th>horse_power</th>\n",
              "      <th>peak_rpm</th>\n",
              "      <th>city_mpg</th>\n",
              "      <th>highway_mpg</th>\n",
              "      <th>price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero giulia</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>13495</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero stelvio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>alfa-romero Quadrifoglio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>hatchback</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>94.5</td>\n",
              "      <td>...</td>\n",
              "      <td>152</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>5K</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100 ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>four</td>\n",
              "      <td>sedan</td>\n",
              "      <td>fwd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.8</td>\n",
              "      <td>...</td>\n",
              "      <td>109</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>5500</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "      <td>13950</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>four</td>\n",
              "      <td>sedan</td>\n",
              "      <td>4wd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.4</td>\n",
              "      <td>...</td>\n",
              "      <td>136</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>5500</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "      <td>17450</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 26 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c00d0d19-9e22-4cfb-b577-96f5148d65b3')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-c00d0d19-9e22-4cfb-b577-96f5148d65b3 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-c00d0d19-9e22-4cfb-b577-96f5148d65b3');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 8
        }
      ],
      "source": [
        "df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "OQMzF_VCgm9D",
        "outputId": "46f61d8d-7431-45f1-87c4-978976dd6224"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 205 entries, 0 to 204\n",
            "Data columns (total 26 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   car_id             205 non-null    int64  \n",
            " 1   symboling          205 non-null    int64  \n",
            " 2   car_name           205 non-null    object \n",
            " 3   fuel_type          205 non-null    object \n",
            " 4   aspiration         205 non-null    object \n",
            " 5   door_number        205 non-null    object \n",
            " 6   car_body           205 non-null    object \n",
            " 7   drive_wheel        205 non-null    object \n",
            " 8   engine_location    205 non-null    object \n",
            " 9   wheel_base         205 non-null    float64\n",
            " 10  car_length         205 non-null    float64\n",
            " 11  car_width          205 non-null    float64\n",
            " 12  car_height         205 non-null    float64\n",
            " 13  curb_weight        205 non-null    int64  \n",
            " 14  engine_type        205 non-null    object \n",
            " 15  cylinder_number    205 non-null    object \n",
            " 16  engine_size        205 non-null    int64  \n",
            " 17  fuel_system        205 non-null    object \n",
            " 18  bore_ratio         205 non-null    float64\n",
            " 19  stroke             205 non-null    float64\n",
            " 20  compression_ratio  205 non-null    float64\n",
            " 21  horse_power        205 non-null    int64  \n",
            " 22  peak_rpm           205 non-null    object \n",
            " 23  city_mpg           205 non-null    int64  \n",
            " 24  highway_mpg        205 non-null    int64  \n",
            " 25  price              205 non-null    object \n",
            "dtypes: float64(7), int64(7), object(12)\n",
            "memory usage: 41.8+ KB\n"
          ]
        }
      ],
      "source": [
        "df.info()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "K_rdsNBMgm9E"
      },
      "source": [
        "## As a part of this case study, we will focus only on `car_name`, `door_number` and `peak_rpm`\n",
        "\n",
        "From df.info(), it is clear that `car_name`, `door_number` and `peak_rpm` are object type without any missing values"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "JNiYJmkAgm9F",
        "outputId": "2a1c127f-817d-4c38-99a2-a01948dc5395"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "toyota corona           6\n",
              "toyota corolla          6\n",
              "peugeot 504             6\n",
              "subaru dl               4\n",
              "mitsubishi mirage g4    3\n",
              "                       ..\n",
              "mazda glc 4             1\n",
              "mazda rx2 coupe         1\n",
              "maxda glc deluxe        1\n",
              "maxda rx3               1\n",
              "volvo 246               1\n",
              "Name: car_name, Length: 147, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 10
        }
      ],
      "source": [
        "df.car_name.value_counts()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "d5keii-qgm9F",
        "outputId": "026f8c36-d572-41c1-a080-a4f723c36fea"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "four    114\n",
              "two      90\n",
              "?         1\n",
              "Name: door_number, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 11
        }
      ],
      "source": [
        "df.door_number.value_counts()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "vDA4Krpigm9G",
        "outputId": "eb0e6d99-90ab-4a39-8c9b-db9bcb22d752"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "5500     36\n",
              "4800     36\n",
              "5K       27\n",
              "5200     21\n",
              "5400     10\n",
              "6K        9\n",
              "4500      7\n",
              "5250      7\n",
              "5800      7\n",
              "5100      5\n",
              "4150      5\n",
              "4200      5\n",
              "4750      4\n",
              "4350      4\n",
              "5,400     3\n",
              "4250      3\n",
              "5900      3\n",
              "4400      3\n",
              "5,200     2\n",
              "6600      2\n",
              "4900      1\n",
              "5,500     1\n",
              "5750      1\n",
              "5600      1\n",
              "4650      1\n",
              "5300      1\n",
              "Name: peak_rpm, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 12
        }
      ],
      "source": [
        "df.peak_rpm.value_counts()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Jsr_x2rfgm9H"
      },
      "source": [
        "**Observations**\n",
        "\n",
        "- `car_name` is a categorical column with 147 categories of cars\n",
        "- It looks like `door_number` is containing one missing value \n",
        "- `peak_rpm` looks like an integer column with some abnormalities."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tAbh0Owkgm9I"
      },
      "source": [
        "## Fixing `door_number` column\n",
        "\n",
        "**Posible Fixes**\n",
        "- Handle the missing value\n",
        "- Possibility to conver to integer column"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LZrGv57Hgm9I"
      },
      "source": [
        "#### Crosstab - It compares the index and columns which yields the count "
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.columns"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "UPltFeBqh8A1",
        "outputId": "cc782c74-415e-42d1-c303-9cc33480aead"
      },
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Index(['car_id', 'symboling', 'car_name', 'fuel_type', 'aspiration',\n",
              "       'door_number', 'car_body', 'drive_wheel', 'engine_location',\n",
              "       'wheel_base', 'car_length', 'car_width', 'car_height', 'curb_weight',\n",
              "       'engine_type', 'cylinder_number', 'engine_size', 'fuel_system',\n",
              "       'bore_ratio', 'stroke', 'compression_ratio', 'horse_power', 'peak_rpm',\n",
              "       'city_mpg', 'highway_mpg', 'price'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {},
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 175
        },
        "id": "-ue-3FpYgm9I",
        "outputId": "e6239d36-6528-44de-aadd-4cf529f044b9"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "car_body     convertible  hardtop  hatchback  sedan  wagon\n",
              "door_number                                               \n",
              "?                      0        0          0      0      1\n",
              "four                   0        0         10     80     24\n",
              "two                    6        8         60     16      0"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-e1c67fd4-c45c-4f8e-9256-09bfe84150e9\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th>car_body</th>\n",
              "      <th>convertible</th>\n",
              "      <th>hardtop</th>\n",
              "      <th>hatchback</th>\n",
              "      <th>sedan</th>\n",
              "      <th>wagon</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>door_number</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>?</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>four</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>10</td>\n",
              "      <td>80</td>\n",
              "      <td>24</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>two</th>\n",
              "      <td>6</td>\n",
              "      <td>8</td>\n",
              "      <td>60</td>\n",
              "      <td>16</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e1c67fd4-c45c-4f8e-9256-09bfe84150e9')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-e1c67fd4-c45c-4f8e-9256-09bfe84150e9 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-e1c67fd4-c45c-4f8e-9256-09bfe84150e9');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 15
        }
      ],
      "source": [
        "# pd.crosstab(index=df['door_number'], columns=df['car_body'])\n",
        "\n",
        "pd.crosstab(df['door_number'], df['car_body'])"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "pd.crosstab(df['door_number'], df['fuel_type'])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 175
        },
        "id": "vwyH9NgmiL4t",
        "outputId": "2d660b54-f2ed-486a-db9b-1d06d4d7b04c"
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "fuel_type    diesel  gas\n",
              "door_number             \n",
              "?                 0    1\n",
              "four             17   97\n",
              "two               3   87"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-6ba725b8-be6e-4c93-998d-f5ce719642aa\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th>fuel_type</th>\n",
              "      <th>diesel</th>\n",
              "      <th>gas</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>door_number</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>?</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>four</th>\n",
              "      <td>17</td>\n",
              "      <td>97</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>two</th>\n",
              "      <td>3</td>\n",
              "      <td>87</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-6ba725b8-be6e-4c93-998d-f5ce719642aa')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-6ba725b8-be6e-4c93-998d-f5ce719642aa button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-6ba725b8-be6e-4c93-998d-f5ce719642aa');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "pd.crosstab(df['door_number'], df['drive_wheel'])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 175
        },
        "id": "IF6MBKC-ihzH",
        "outputId": "74d7ba72-1ce6-40a9-8366-8922550e7837"
      },
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "drive_wheel  4wd  fwd  rwd\n",
              "door_number               \n",
              "?              0    1    0\n",
              "four           7   68   39\n",
              "two            2   51   37"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-add36b17-56c7-4720-b6e4-461b25084d50\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th>drive_wheel</th>\n",
              "      <th>4wd</th>\n",
              "      <th>fwd</th>\n",
              "      <th>rwd</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>door_number</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>?</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>four</th>\n",
              "      <td>7</td>\n",
              "      <td>68</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>two</th>\n",
              "      <td>2</td>\n",
              "      <td>51</td>\n",
              "      <td>37</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-add36b17-56c7-4720-b6e4-461b25084d50')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-add36b17-56c7-4720-b6e4-461b25084d50 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-add36b17-56c7-4720-b6e4-461b25084d50');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 175
        },
        "id": "e-7AAHa8gm9J",
        "outputId": "4c0ea713-89b4-47fb-fd7d-2fdc46a5601d"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "engine_location  front  rear\n",
              "door_number                 \n",
              "?                    1     0\n",
              "four               114     0\n",
              "two                 87     3"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-9e8d4ab2-3dc2-4bcf-9932-49c4ef56384c\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th>engine_location</th>\n",
              "      <th>front</th>\n",
              "      <th>rear</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>door_number</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>?</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>four</th>\n",
              "      <td>114</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>two</th>\n",
              "      <td>87</td>\n",
              "      <td>3</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9e8d4ab2-3dc2-4bcf-9932-49c4ef56384c')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-9e8d4ab2-3dc2-4bcf-9932-49c4ef56384c button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-9e8d4ab2-3dc2-4bcf-9932-49c4ef56384c');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 16
        }
      ],
      "source": [
        "pd.crosstab(df['door_number'], df['engine_location'])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0vMZApDVgm9J"
      },
      "source": [
        "#### Replace"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "7m7eeiXMgm9K",
        "outputId": "306bc82a-50fb-4290-9cad-f0364f9bd2e3"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "four    115\n",
              "two      90\n",
              "Name: door_number, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 18
        }
      ],
      "source": [
        "# df.replace(to_replace='old', value='new', regex=False, inplace=True)\n",
        "# df.replace(to_replace=r'regex', value='new', regex=True, inplace=True)\n",
        "\n",
        "df['door_number'].replace(to_replace='?', value='four', regex=False, inplace=True)\n",
        "\n",
        "df.door_number.value_counts()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 352
        },
        "id": "ylh06dLQgm9M",
        "outputId": "b01b6255-1e8a-43f7-e1e1-ef4ea5c0bc58"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   car_id  symboling                  car_name fuel_type aspiration  \\\n",
              "0       1          3        alfa-romero giulia       gas        std   \n",
              "1       2          3       alfa-romero stelvio       gas        std   \n",
              "2       3          1  alfa-romero Quadrifoglio       gas        std   \n",
              "3       4          2               audi 100 ls       gas        std   \n",
              "4       5          2                audi 100ls       gas        std   \n",
              "\n",
              "  door_number     car_body drive_wheel engine_location  wheel_base  ...  \\\n",
              "0         two  convertible         rwd           front        88.6  ...   \n",
              "1         two  convertible         rwd           front        88.6  ...   \n",
              "2         two    hatchback         rwd           front        94.5  ...   \n",
              "3        four        sedan         fwd           front        99.8  ...   \n",
              "4        four        sedan         4wd           front        99.4  ...   \n",
              "\n",
              "   engine_size  fuel_system  bore_ratio  stroke compression_ratio horse_power  \\\n",
              "0          130         mpfi        3.47    2.68               9.0         111   \n",
              "1          130         mpfi        3.47    2.68               9.0         111   \n",
              "2          152         mpfi        2.68    3.47               9.0         154   \n",
              "3          109         mpfi        3.19    3.40              10.0         102   \n",
              "4          136         mpfi        3.19    3.40               8.0         115   \n",
              "\n",
              "   peak_rpm city_mpg  highway_mpg  price  \n",
              "0        5K       21           27  13495  \n",
              "1        5K       21           27  16500  \n",
              "2        5K       19           26  16500  \n",
              "3      5500       24           30  13950  \n",
              "4      5500       18           22  17450  \n",
              "\n",
              "[5 rows x 26 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-17edded7-2b0f-4cb6-aa62-8ea9e598175c\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>car_id</th>\n",
              "      <th>symboling</th>\n",
              "      <th>car_name</th>\n",
              "      <th>fuel_type</th>\n",
              "      <th>aspiration</th>\n",
              "      <th>door_number</th>\n",
              "      <th>car_body</th>\n",
              "      <th>drive_wheel</th>\n",
              "      <th>engine_location</th>\n",
              "      <th>wheel_base</th>\n",
              "      <th>...</th>\n",
              "      <th>engine_size</th>\n",
              "      <th>fuel_system</th>\n",
              "      <th>bore_ratio</th>\n",
              "      <th>stroke</th>\n",
              "      <th>compression_ratio</th>\n",
              "      <th>horse_power</th>\n",
              "      <th>peak_rpm</th>\n",
              "      <th>city_mpg</th>\n",
              "      <th>highway_mpg</th>\n",
              "      <th>price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero giulia</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>13495</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero stelvio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>alfa-romero Quadrifoglio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>two</td>\n",
              "      <td>hatchback</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>94.5</td>\n",
              "      <td>...</td>\n",
              "      <td>152</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>5K</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100 ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>four</td>\n",
              "      <td>sedan</td>\n",
              "      <td>fwd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.8</td>\n",
              "      <td>...</td>\n",
              "      <td>109</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>5500</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "      <td>13950</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>four</td>\n",
              "      <td>sedan</td>\n",
              "      <td>4wd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.4</td>\n",
              "      <td>...</td>\n",
              "      <td>136</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>5500</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "      <td>17450</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 26 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-17edded7-2b0f-4cb6-aa62-8ea9e598175c')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-17edded7-2b0f-4cb6-aa62-8ea9e598175c button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-17edded7-2b0f-4cb6-aa62-8ea9e598175c');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 19
        }
      ],
      "source": [
        "df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "bxDMqSlNgm9M",
        "outputId": "c005e616-e071-436d-c42c-253069d435db"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0      2\n",
              "1      2\n",
              "2      2\n",
              "3      4\n",
              "4      4\n",
              "      ..\n",
              "200    4\n",
              "201    4\n",
              "202    4\n",
              "203    4\n",
              "204    4\n",
              "Name: door_number, Length: 205, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 20
        }
      ],
      "source": [
        "# df['door_number'].replace(to_replace='four', value='4', regex=False, inplace=True)\n",
        "# df['door_number'].replace(to_replace='two', value='2', regex=False, inplace=True)\n",
        "\n",
        "df['door_number'].apply(lambda x : 4 if x=='four' else 2)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "scrolled": true,
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "7pHSlF65gm9O",
        "outputId": "00da0222-b969-4ad9-f375-8f6e852a66f4"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "four    115\n",
              "two      90\n",
              "Name: door_number, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 21
        }
      ],
      "source": [
        "df['door_number'].value_counts()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Bru4bgPlgm9P",
        "outputId": "fdb78bde-77bd-463e-a755-a67bb681b47a"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "4    115\n",
              "2     90\n",
              "Name: door_number, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 22
        }
      ],
      "source": [
        "df['door_number'].apply(lambda x : 4 if x=='four' else 2).value_counts()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "metadata": {
        "id": "5ZhL0W2Ggm9S"
      },
      "outputs": [],
      "source": [
        "df['door_number'] = df['door_number'].apply(lambda x : 4 if x=='four' else 2)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "metadata": {
        "scrolled": true,
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 352
        },
        "id": "ypN8D8Hwgm9T",
        "outputId": "dec52666-d64a-44e9-ec56-b83410e003f1"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   car_id  symboling                  car_name fuel_type aspiration  \\\n",
              "0       1          3        alfa-romero giulia       gas        std   \n",
              "1       2          3       alfa-romero stelvio       gas        std   \n",
              "2       3          1  alfa-romero Quadrifoglio       gas        std   \n",
              "3       4          2               audi 100 ls       gas        std   \n",
              "4       5          2                audi 100ls       gas        std   \n",
              "\n",
              "   door_number     car_body drive_wheel engine_location  wheel_base  ...  \\\n",
              "0            2  convertible         rwd           front        88.6  ...   \n",
              "1            2  convertible         rwd           front        88.6  ...   \n",
              "2            2    hatchback         rwd           front        94.5  ...   \n",
              "3            4        sedan         fwd           front        99.8  ...   \n",
              "4            4        sedan         4wd           front        99.4  ...   \n",
              "\n",
              "   engine_size  fuel_system  bore_ratio  stroke compression_ratio horse_power  \\\n",
              "0          130         mpfi        3.47    2.68               9.0         111   \n",
              "1          130         mpfi        3.47    2.68               9.0         111   \n",
              "2          152         mpfi        2.68    3.47               9.0         154   \n",
              "3          109         mpfi        3.19    3.40              10.0         102   \n",
              "4          136         mpfi        3.19    3.40               8.0         115   \n",
              "\n",
              "   peak_rpm city_mpg  highway_mpg  price  \n",
              "0        5K       21           27  13495  \n",
              "1        5K       21           27  16500  \n",
              "2        5K       19           26  16500  \n",
              "3      5500       24           30  13950  \n",
              "4      5500       18           22  17450  \n",
              "\n",
              "[5 rows x 26 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-f3710c61-1221-42b7-ada3-9e85d32fcfdf\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>car_id</th>\n",
              "      <th>symboling</th>\n",
              "      <th>car_name</th>\n",
              "      <th>fuel_type</th>\n",
              "      <th>aspiration</th>\n",
              "      <th>door_number</th>\n",
              "      <th>car_body</th>\n",
              "      <th>drive_wheel</th>\n",
              "      <th>engine_location</th>\n",
              "      <th>wheel_base</th>\n",
              "      <th>...</th>\n",
              "      <th>engine_size</th>\n",
              "      <th>fuel_system</th>\n",
              "      <th>bore_ratio</th>\n",
              "      <th>stroke</th>\n",
              "      <th>compression_ratio</th>\n",
              "      <th>horse_power</th>\n",
              "      <th>peak_rpm</th>\n",
              "      <th>city_mpg</th>\n",
              "      <th>highway_mpg</th>\n",
              "      <th>price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero giulia</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>2</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>13495</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero stelvio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>2</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5K</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>alfa-romero Quadrifoglio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>2</td>\n",
              "      <td>hatchback</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>94.5</td>\n",
              "      <td>...</td>\n",
              "      <td>152</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>5K</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100 ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>4</td>\n",
              "      <td>sedan</td>\n",
              "      <td>fwd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.8</td>\n",
              "      <td>...</td>\n",
              "      <td>109</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>5500</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "      <td>13950</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>4</td>\n",
              "      <td>sedan</td>\n",
              "      <td>4wd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.4</td>\n",
              "      <td>...</td>\n",
              "      <td>136</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>5500</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "      <td>17450</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 26 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-f3710c61-1221-42b7-ada3-9e85d32fcfdf')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-f3710c61-1221-42b7-ada3-9e85d32fcfdf button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-f3710c61-1221-42b7-ada3-9e85d32fcfdf');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 24
        }
      ],
      "source": [
        "df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "metadata": {
        "id": "Xcvdn1n1gm9U"
      },
      "outputs": [],
      "source": [
        "df['door_number'] = df['door_number'].astype('int')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 26,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "yBQ4BNjGgm9V",
        "outputId": "7a3710bc-240e-4806-9114-e87f815df1bc"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 205 entries, 0 to 204\n",
            "Data columns (total 26 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   car_id             205 non-null    int64  \n",
            " 1   symboling          205 non-null    int64  \n",
            " 2   car_name           205 non-null    object \n",
            " 3   fuel_type          205 non-null    object \n",
            " 4   aspiration         205 non-null    object \n",
            " 5   door_number        205 non-null    int64  \n",
            " 6   car_body           205 non-null    object \n",
            " 7   drive_wheel        205 non-null    object \n",
            " 8   engine_location    205 non-null    object \n",
            " 9   wheel_base         205 non-null    float64\n",
            " 10  car_length         205 non-null    float64\n",
            " 11  car_width          205 non-null    float64\n",
            " 12  car_height         205 non-null    float64\n",
            " 13  curb_weight        205 non-null    int64  \n",
            " 14  engine_type        205 non-null    object \n",
            " 15  cylinder_number    205 non-null    object \n",
            " 16  engine_size        205 non-null    int64  \n",
            " 17  fuel_system        205 non-null    object \n",
            " 18  bore_ratio         205 non-null    float64\n",
            " 19  stroke             205 non-null    float64\n",
            " 20  compression_ratio  205 non-null    float64\n",
            " 21  horse_power        205 non-null    int64  \n",
            " 22  peak_rpm           205 non-null    object \n",
            " 23  city_mpg           205 non-null    int64  \n",
            " 24  highway_mpg        205 non-null    int64  \n",
            " 25  price              205 non-null    object \n",
            "dtypes: float64(7), int64(8), object(11)\n",
            "memory usage: 41.8+ KB\n"
          ]
        }
      ],
      "source": [
        "df.info()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9Ud3r_REgm9V"
      },
      "source": [
        "## Fixing `peak_rpm`\n",
        "\n",
        "**Posible Fixes**\n",
        "- `5K` should be replaced with `5000`\n",
        "- `5,500` should be replaced with `5500`\n",
        "- Convert to numerical column"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 311
        },
        "id": "y2WLAhSRgm9W",
        "outputId": "c447ed08-f345-40ba-e54b-54f5fd8d8f0f"
      },
      "outputs": [
        {
          "output_type": "error",
          "ename": "ValueError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-27-081e3698fb9f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m## Run the code and understand the output\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'peak_rpm'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreplace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'K'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m1000\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'K'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/pandas/core/series.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, func, convert_dtype, args, **kwargs)\u001b[0m\n\u001b[1;32m   4355\u001b[0m         \u001b[0mdtype\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mfloat64\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4356\u001b[0m         \"\"\"\n\u001b[0;32m-> 4357\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mSeriesApply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconvert_dtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   4358\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4359\u001b[0m     def _reduce(\n",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m   1041\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_str\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1042\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1043\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_standard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1044\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1045\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0magg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply_standard\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m   1099\u001b[0m                     \u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1100\u001b[0m                     \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m  \u001b[0;31m# type: ignore[arg-type]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1101\u001b[0;31m                     \u001b[0mconvert\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert_dtype\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1102\u001b[0m                 )\n\u001b[1;32m   1103\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/pandas/_libs/lib.pyx\u001b[0m in \u001b[0;36mpandas._libs.lib.map_infer\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32m<ipython-input-27-081e3698fb9f>\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m## Run the code and understand the output\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'peak_rpm'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreplace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'K'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m1000\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'K'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: '5,500'"
          ]
        }
      ],
      "source": [
        "## Run the code and understand the output\n",
        "\n",
        "df['peak_rpm'].apply(lambda x : (int(x.replace('K', '')) * 1000) if 'K' in x else int(x))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 28,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "6r1jA2DHgm9X",
        "outputId": "956f3013-4434-414b-fa06-2c379872e3c3"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0      5000\n",
              "1      5000\n",
              "2      5000\n",
              "3      5500\n",
              "4      5500\n",
              "       ... \n",
              "200    5400\n",
              "201    5300\n",
              "202    5500\n",
              "203    4800\n",
              "204    5400\n",
              "Name: peak_rpm, Length: 205, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 28
        }
      ],
      "source": [
        "df['peak_rpm'].apply(lambda x : (int(x.replace('K', '')) * 1000) if 'K' in x else int(x.replace(',', '')) if ',' in x else int(x))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 29,
      "metadata": {
        "id": "431_z6oWgm9Y"
      },
      "outputs": [],
      "source": [
        "df['peak_rpm'] = df['peak_rpm'].apply(lambda x : (int(x.replace('K', '')) * 1000) if 'K' in x else int(x.replace(',', '')) if ',' in x else int(x))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 30,
      "metadata": {
        "id": "25hBVuX_gm9Y"
      },
      "outputs": [],
      "source": [
        "df['peak_rpm'] = df['peak_rpm'].astype('int')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 31,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "S1hlZU5ngm9Z",
        "outputId": "b2d885c6-319a-40bb-e97f-020c9110760b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 205 entries, 0 to 204\n",
            "Data columns (total 26 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   car_id             205 non-null    int64  \n",
            " 1   symboling          205 non-null    int64  \n",
            " 2   car_name           205 non-null    object \n",
            " 3   fuel_type          205 non-null    object \n",
            " 4   aspiration         205 non-null    object \n",
            " 5   door_number        205 non-null    int64  \n",
            " 6   car_body           205 non-null    object \n",
            " 7   drive_wheel        205 non-null    object \n",
            " 8   engine_location    205 non-null    object \n",
            " 9   wheel_base         205 non-null    float64\n",
            " 10  car_length         205 non-null    float64\n",
            " 11  car_width          205 non-null    float64\n",
            " 12  car_height         205 non-null    float64\n",
            " 13  curb_weight        205 non-null    int64  \n",
            " 14  engine_type        205 non-null    object \n",
            " 15  cylinder_number    205 non-null    object \n",
            " 16  engine_size        205 non-null    int64  \n",
            " 17  fuel_system        205 non-null    object \n",
            " 18  bore_ratio         205 non-null    float64\n",
            " 19  stroke             205 non-null    float64\n",
            " 20  compression_ratio  205 non-null    float64\n",
            " 21  horse_power        205 non-null    int64  \n",
            " 22  peak_rpm           205 non-null    int64  \n",
            " 23  city_mpg           205 non-null    int64  \n",
            " 24  highway_mpg        205 non-null    int64  \n",
            " 25  price              205 non-null    object \n",
            "dtypes: float64(7), int64(9), object(10)\n",
            "memory usage: 41.8+ KB\n"
          ]
        }
      ],
      "source": [
        "df.info()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 32,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "0VqMS9PIgm9Z",
        "outputId": "58b15942-7de7-473e-aef5-be7cf5ad754a"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "four      159\n",
              "six        24\n",
              "five       11\n",
              "eight       5\n",
              "two         4\n",
              "three       1\n",
              "twelve      1\n",
              "Name: cylinder_number, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 32
        }
      ],
      "source": [
        "df.cylinder_number.value_counts()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vCXCJTh1gm9Z"
      },
      "source": [
        "## Fixing `car_name`\n",
        "\n",
        "**Posible Fixes**\n",
        "- Extract Company Name from car name\n",
        "- Observe problems in Company Names"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 33,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 352
        },
        "id": "_xaQV-f8gm9a",
        "outputId": "2bc2de5d-73c3-4ce1-ed52-56558455a777"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   car_id  symboling                  car_name fuel_type aspiration  \\\n",
              "0       1          3        alfa-romero giulia       gas        std   \n",
              "1       2          3       alfa-romero stelvio       gas        std   \n",
              "2       3          1  alfa-romero Quadrifoglio       gas        std   \n",
              "3       4          2               audi 100 ls       gas        std   \n",
              "4       5          2                audi 100ls       gas        std   \n",
              "\n",
              "   door_number     car_body drive_wheel engine_location  wheel_base  ...  \\\n",
              "0            2  convertible         rwd           front        88.6  ...   \n",
              "1            2  convertible         rwd           front        88.6  ...   \n",
              "2            2    hatchback         rwd           front        94.5  ...   \n",
              "3            4        sedan         fwd           front        99.8  ...   \n",
              "4            4        sedan         4wd           front        99.4  ...   \n",
              "\n",
              "   engine_size  fuel_system  bore_ratio  stroke compression_ratio horse_power  \\\n",
              "0          130         mpfi        3.47    2.68               9.0         111   \n",
              "1          130         mpfi        3.47    2.68               9.0         111   \n",
              "2          152         mpfi        2.68    3.47               9.0         154   \n",
              "3          109         mpfi        3.19    3.40              10.0         102   \n",
              "4          136         mpfi        3.19    3.40               8.0         115   \n",
              "\n",
              "   peak_rpm city_mpg  highway_mpg  price  \n",
              "0      5000       21           27  13495  \n",
              "1      5000       21           27  16500  \n",
              "2      5000       19           26  16500  \n",
              "3      5500       24           30  13950  \n",
              "4      5500       18           22  17450  \n",
              "\n",
              "[5 rows x 26 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-e2be1989-77e0-4861-b3a5-fa84da76a736\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>car_id</th>\n",
              "      <th>symboling</th>\n",
              "      <th>car_name</th>\n",
              "      <th>fuel_type</th>\n",
              "      <th>aspiration</th>\n",
              "      <th>door_number</th>\n",
              "      <th>car_body</th>\n",
              "      <th>drive_wheel</th>\n",
              "      <th>engine_location</th>\n",
              "      <th>wheel_base</th>\n",
              "      <th>...</th>\n",
              "      <th>engine_size</th>\n",
              "      <th>fuel_system</th>\n",
              "      <th>bore_ratio</th>\n",
              "      <th>stroke</th>\n",
              "      <th>compression_ratio</th>\n",
              "      <th>horse_power</th>\n",
              "      <th>peak_rpm</th>\n",
              "      <th>city_mpg</th>\n",
              "      <th>highway_mpg</th>\n",
              "      <th>price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero giulia</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>2</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5000</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>13495</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>alfa-romero stelvio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>2</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>88.6</td>\n",
              "      <td>...</td>\n",
              "      <td>130</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5000</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>alfa-romero Quadrifoglio</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>2</td>\n",
              "      <td>hatchback</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>94.5</td>\n",
              "      <td>...</td>\n",
              "      <td>152</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>5000</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "      <td>16500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100 ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>4</td>\n",
              "      <td>sedan</td>\n",
              "      <td>fwd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.8</td>\n",
              "      <td>...</td>\n",
              "      <td>109</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>5500</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "      <td>13950</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>audi 100ls</td>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>4</td>\n",
              "      <td>sedan</td>\n",
              "      <td>4wd</td>\n",
              "      <td>front</td>\n",
              "      <td>99.4</td>\n",
              "      <td>...</td>\n",
              "      <td>136</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>5500</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "      <td>17450</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 26 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e2be1989-77e0-4861-b3a5-fa84da76a736')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-e2be1989-77e0-4861-b3a5-fa84da76a736 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-e2be1989-77e0-4861-b3a5-fa84da76a736');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 33
        }
      ],
      "source": [
        "df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 34,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "4YVJZjNWgm9a",
        "outputId": "50c41be1-2a2f-4a6f-931b-413eb68709f0"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0            alfa-romero giulia\n",
              "1           alfa-romero stelvio\n",
              "2      alfa-romero Quadrifoglio\n",
              "3                   audi 100 ls\n",
              "4                    audi 100ls\n",
              "                 ...           \n",
              "200             volvo 145e (sw)\n",
              "201                 volvo 144ea\n",
              "202                 volvo 244dl\n",
              "203                   volvo 246\n",
              "204                 volvo 264gl\n",
              "Name: car_name, Length: 205, dtype: object"
            ]
          },
          "metadata": {},
          "execution_count": 34
        }
      ],
      "source": [
        "df.car_name"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 35,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "egcqKzT-gm9b",
        "outputId": "3b5afcf1-6a59-4307-e863-8e10d16d04c7"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0           alfa-romero giulia\n",
              "1          alfa-romero stelvio\n",
              "2     alfa-romero Quadrifoglio\n",
              "3                  audi 100 ls\n",
              "4                   audi 100ls\n",
              "5                     audi fox\n",
              "6                   audi 100ls\n",
              "7                    audi 5000\n",
              "8                    audi 4000\n",
              "9          audi 5000s (diesel)\n",
              "10                    bmw 320i\n",
              "11                    bmw 320i\n",
              "12                      bmw x1\n",
              "13                      bmw x3\n",
              "14                      bmw z4\n",
              "15                      bmw x4\n",
              "16                      bmw x5\n",
              "17                      bmw x3\n",
              "18            chevrolet impala\n",
              "19       chevrolet monte carlo\n",
              "Name: car_name, dtype: object"
            ]
          },
          "metadata": {},
          "execution_count": 35
        }
      ],
      "source": [
        "df.car_name[:20]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 36,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Rp_8GWjGgm9b",
        "outputId": "1eb26773-54de-4bb4-d253-86d72c7f368f"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0            [alfa-romero, giulia]\n",
              "1           [alfa-romero, stelvio]\n",
              "2      [alfa-romero, Quadrifoglio]\n",
              "3                  [audi, 100, ls]\n",
              "4                    [audi, 100ls]\n",
              "                  ...             \n",
              "200            [volvo, 145e, (sw)]\n",
              "201                 [volvo, 144ea]\n",
              "202                 [volvo, 244dl]\n",
              "203                   [volvo, 246]\n",
              "204                 [volvo, 264gl]\n",
              "Name: car_name, Length: 205, dtype: object"
            ]
          },
          "metadata": {},
          "execution_count": 36
        }
      ],
      "source": [
        "df.car_name.apply(lambda x : x.split())"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 37,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "a2Dz1vuTgm9b",
        "outputId": "4fe8018d-7517-4c1b-c29b-aa7a6bbe9351"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0      alfa-romero\n",
              "1      alfa-romero\n",
              "2      alfa-romero\n",
              "3             audi\n",
              "4             audi\n",
              "          ...     \n",
              "200          volvo\n",
              "201          volvo\n",
              "202          volvo\n",
              "203          volvo\n",
              "204          volvo\n",
              "Name: car_name, Length: 205, dtype: object"
            ]
          },
          "metadata": {},
          "execution_count": 37
        }
      ],
      "source": [
        "df.car_name.apply(lambda x : x.split()[0])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 38,
      "metadata": {
        "id": "QkRVRdZEgm9c"
      },
      "outputs": [],
      "source": [
        "df['car_company'] = df.car_name.apply(lambda x : x.split()[0])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 39,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LKn1jf9jgm9c",
        "outputId": "31e1bea7-ac6b-4e26-fd64-4d84a34b5b10"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "toyota         31\n",
              "nissan         17\n",
              "mazda          15\n",
              "honda          13\n",
              "mitsubishi     13\n",
              "subaru         12\n",
              "peugeot        11\n",
              "volvo          11\n",
              "volkswagen      9\n",
              "dodge           9\n",
              "buick           8\n",
              "bmw             8\n",
              "audi            7\n",
              "plymouth        7\n",
              "saab            6\n",
              "isuzu           4\n",
              "porsche         4\n",
              "alfa-romero     3\n",
              "chevrolet       3\n",
              "jaguar          3\n",
              "vw              2\n",
              "maxda           2\n",
              "renault         2\n",
              "toyouta         1\n",
              "vokswagen       1\n",
              "Nissan          1\n",
              "mercury         1\n",
              "porcshce        1\n",
              "Name: car_company, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 39
        }
      ],
      "source": [
        "df.car_company.value_counts()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PnVm7j-Sgm9c"
      },
      "source": [
        "**Observations**\n",
        "\n",
        "Notice that some **car_company names are misspelled**  \n",
        "- vw and vokswagen should be volkswagen \n",
        "- porcshce should be porsche \n",
        "- toyouta should be toyota\n",
        "- Nissan should be nissan \n",
        "- maxda should be mazda\n",
        "\n",
        "This is a data quality issue, let's solve it."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 45,
      "metadata": {
        "id": "pRfziybfgm9d"
      },
      "outputs": [],
      "source": [
        "# replacing misspelled car_company names\n",
        "\n",
        "# volkswagen\n",
        "df.loc[(df['car_company'] == \"vw\") | (df['car_company'] == \"vokswagen\"), 'car_company'] = 'volkswagen'\n",
        "\n",
        "# porsche\n",
        "df.loc[df['car_company'] == \"porcshce\", 'car_company'] = 'porsche'\n",
        "\n",
        "# toyota\n",
        "df.loc[df['car_company'] == \"toyouta\", 'car_company'] = 'toyota'\n",
        "\n",
        "# nissan\n",
        "df.loc[df['car_company'] == \"Nissan\", 'car_company'] = 'nissan'\n",
        "\n",
        "# mazda\n",
        "df.loc[df['car_company'] == \"maxda\", 'car_company'] = 'mazda'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 46,
      "metadata": {
        "id": "hQSDNo51gm9e"
      },
      "outputs": [],
      "source": [
        "# df['car_company'].apply(lambda x : \"volkswagen\" if x == \"vw\" or x == \"vokswagen\" else \n",
        "#                        \"porsche\" if x == \"porcshce\" else\n",
        "#                        \"toyota\" if x == \"toyouta\" else\n",
        "#                        \"nissan\" if x == \"Nissan\" else\n",
        "#                        \"mazda\" if x == \"maxda\" else x)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# company_dictionary = {\n",
        "#                       \"vw\" : \"volkswagen\", \n",
        "#                       \"vokswagen\" : \"volkswagen\", \n",
        "#                       \"porcshce\" : \"porsche\", \n",
        "#                       \"toyouta\" : \"toyota\", \n",
        "#                       \"Nissan\" : \"nissan\",\n",
        "#                       \"maxda\" : \"mazda\"\n",
        "#                       }\n",
        "\n",
        "# df['car_company'].apply(lambda x : company_dictionary[x] if x in company_dictionary.keys() else x).value_counts()"
      ],
      "metadata": {
        "id": "zsqJckQmke0M"
      },
      "execution_count": 47,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": 48,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ztpXU10agm9e",
        "outputId": "647281ab-2b5c-4f9b-c1f5-ea0ca8aac4b1"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "toyota         32\n",
              "nissan         18\n",
              "mazda          17\n",
              "mitsubishi     13\n",
              "honda          13\n",
              "volkswagen     12\n",
              "subaru         12\n",
              "peugeot        11\n",
              "volvo          11\n",
              "dodge           9\n",
              "buick           8\n",
              "bmw             8\n",
              "audi            7\n",
              "plymouth        7\n",
              "saab            6\n",
              "porsche         5\n",
              "isuzu           4\n",
              "jaguar          3\n",
              "chevrolet       3\n",
              "alfa-romero     3\n",
              "renault         2\n",
              "mercury         1\n",
              "Name: car_company, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 48
        }
      ],
      "source": [
        "df.car_company.value_counts()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0sEOXOQGgm9e"
      },
      "source": [
        "#### Dropping a column"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 49,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ZYICrJMRgm9f",
        "outputId": "993efc90-9a6a-45f7-ca73-321b09b24993"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Index(['car_id', 'symboling', 'car_name', 'fuel_type', 'aspiration',\n",
              "       'door_number', 'car_body', 'drive_wheel', 'engine_location',\n",
              "       'wheel_base', 'car_length', 'car_width', 'car_height', 'curb_weight',\n",
              "       'engine_type', 'cylinder_number', 'engine_size', 'fuel_system',\n",
              "       'bore_ratio', 'stroke', 'compression_ratio', 'horse_power', 'peak_rpm',\n",
              "       'city_mpg', 'highway_mpg', 'price', 'car_company'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {},
          "execution_count": 49
        }
      ],
      "source": [
        "df.columns"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 50,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "XAO9cUjpgm9f",
        "outputId": "40580161-77de-4a40-c845-405fe62c2fe1"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Index(['car_id', 'symboling', 'fuel_type', 'aspiration', 'door_number',\n",
              "       'car_body', 'drive_wheel', 'engine_location', 'wheel_base',\n",
              "       'car_length', 'car_width', 'car_height', 'curb_weight', 'engine_type',\n",
              "       'cylinder_number', 'engine_size', 'fuel_system', 'bore_ratio', 'stroke',\n",
              "       'compression_ratio', 'horse_power', 'peak_rpm', 'city_mpg',\n",
              "       'highway_mpg', 'price', 'car_company'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {},
          "execution_count": 50
        }
      ],
      "source": [
        "df.drop('car_name', axis=1, inplace=True)\n",
        "\n",
        "df.columns"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oAiXyeoQgm9f"
      },
      "source": [
        "## Filtering Categorical and Numerical Columns"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "PsLwfBergm9g",
        "outputId": "c47ab69c-3607-419e-f25a-a676605672b3"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>fuel_type</th>\n",
              "      <th>aspiration</th>\n",
              "      <th>car_body</th>\n",
              "      <th>drive_wheel</th>\n",
              "      <th>engine_location</th>\n",
              "      <th>engine_type</th>\n",
              "      <th>cylinder_number</th>\n",
              "      <th>fuel_system</th>\n",
              "      <th>price</th>\n",
              "      <th>car_company</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>dohc</td>\n",
              "      <td>four</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>13495</td>\n",
              "      <td>alfa-romero</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>convertible</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>dohc</td>\n",
              "      <td>four</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>16500</td>\n",
              "      <td>alfa-romero</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>hatchback</td>\n",
              "      <td>rwd</td>\n",
              "      <td>front</td>\n",
              "      <td>ohcv</td>\n",
              "      <td>six</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>16500</td>\n",
              "      <td>alfa-romero</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>sedan</td>\n",
              "      <td>fwd</td>\n",
              "      <td>front</td>\n",
              "      <td>ohc</td>\n",
              "      <td>four</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>13950</td>\n",
              "      <td>audi</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>gas</td>\n",
              "      <td>std</td>\n",
              "      <td>sedan</td>\n",
              "      <td>4wd</td>\n",
              "      <td>front</td>\n",
              "      <td>ohc</td>\n",
              "      <td>five</td>\n",
              "      <td>mpfi</td>\n",
              "      <td>17450</td>\n",
              "      <td>audi</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  fuel_type aspiration     car_body drive_wheel engine_location engine_type  \\\n",
              "0       gas        std  convertible         rwd           front        dohc   \n",
              "1       gas        std  convertible         rwd           front        dohc   \n",
              "2       gas        std    hatchback         rwd           front        ohcv   \n",
              "3       gas        std        sedan         fwd           front         ohc   \n",
              "4       gas        std        sedan         4wd           front         ohc   \n",
              "\n",
              "  cylinder_number fuel_system  price  car_company  \n",
              "0            four        mpfi  13495  alfa-romero  \n",
              "1            four        mpfi  16500  alfa-romero  \n",
              "2             six        mpfi  16500  alfa-romero  \n",
              "3            four        mpfi  13950         audi  \n",
              "4            five        mpfi  17450         audi  "
            ]
          },
          "execution_count": 40,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "categorical_df = df.select_dtypes(include=['object'])\n",
        "\n",
        "categorical_df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "8QzaFWtXgm9g",
        "outputId": "e13da301-7322-4fc0-d42c-6ed38b1e5c16"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>car_id</th>\n",
              "      <th>symboling</th>\n",
              "      <th>wheel_base</th>\n",
              "      <th>car_length</th>\n",
              "      <th>car_width</th>\n",
              "      <th>car_height</th>\n",
              "      <th>curb_weight</th>\n",
              "      <th>engine_size</th>\n",
              "      <th>bore_ratio</th>\n",
              "      <th>stroke</th>\n",
              "      <th>compression_ratio</th>\n",
              "      <th>horse_power</th>\n",
              "      <th>city_mpg</th>\n",
              "      <th>highway_mpg</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>88.6</td>\n",
              "      <td>168.8</td>\n",
              "      <td>64.1</td>\n",
              "      <td>48.8</td>\n",
              "      <td>2548</td>\n",
              "      <td>130</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>88.6</td>\n",
              "      <td>168.8</td>\n",
              "      <td>64.1</td>\n",
              "      <td>48.8</td>\n",
              "      <td>2548</td>\n",
              "      <td>130</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>94.5</td>\n",
              "      <td>171.2</td>\n",
              "      <td>65.5</td>\n",
              "      <td>52.4</td>\n",
              "      <td>2823</td>\n",
              "      <td>152</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>99.8</td>\n",
              "      <td>176.6</td>\n",
              "      <td>66.2</td>\n",
              "      <td>54.3</td>\n",
              "      <td>2337</td>\n",
              "      <td>109</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>99.4</td>\n",
              "      <td>176.6</td>\n",
              "      <td>66.4</td>\n",
              "      <td>54.3</td>\n",
              "      <td>2824</td>\n",
              "      <td>136</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   car_id  symboling  wheel_base  car_length  car_width  car_height  \\\n",
              "0       1          3        88.6       168.8       64.1        48.8   \n",
              "1       2          3        88.6       168.8       64.1        48.8   \n",
              "2       3          1        94.5       171.2       65.5        52.4   \n",
              "3       4          2        99.8       176.6       66.2        54.3   \n",
              "4       5          2        99.4       176.6       66.4        54.3   \n",
              "\n",
              "   curb_weight  engine_size  bore_ratio  stroke  compression_ratio  \\\n",
              "0         2548          130        3.47    2.68                9.0   \n",
              "1         2548          130        3.47    2.68                9.0   \n",
              "2         2823          152        2.68    3.47                9.0   \n",
              "3         2337          109        3.19    3.40               10.0   \n",
              "4         2824          136        3.19    3.40                8.0   \n",
              "\n",
              "   horse_power  city_mpg  highway_mpg  \n",
              "0          111        21           27  \n",
              "1          111        21           27  \n",
              "2          154        19           26  \n",
              "3          102        24           30  \n",
              "4          115        18           22  "
            ]
          },
          "execution_count": 41,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "numerical_df = df.select_dtypes(include=['int64', 'float64'])\n",
        "\n",
        "numerical_df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "m7eJzNLrgm9h",
        "outputId": "5e7d78a3-aa1c-43cc-c31c-7c28de4343b2"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "10\n",
            "14\n"
          ]
        }
      ],
      "source": [
        "print(len(categorical_df.columns))\n",
        "print(len(numerical_df.columns))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "vKZRtB_Kgm9h",
        "outputId": "f1591d37-b524-4826-97fb-c7c82a0b47f1"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "26\n"
          ]
        }
      ],
      "source": [
        "print(len(df.columns))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "0j4mil85gm9i",
        "outputId": "f541e890-f634-4c83-8077-5f6f2db96f0c"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "car_id                 int64\n",
              "symboling              int64\n",
              "fuel_type             object\n",
              "aspiration            object\n",
              "door_number            int32\n",
              "car_body              object\n",
              "drive_wheel           object\n",
              "engine_location       object\n",
              "wheel_base           float64\n",
              "car_length           float64\n",
              "car_width            float64\n",
              "car_height           float64\n",
              "curb_weight            int64\n",
              "engine_type           object\n",
              "cylinder_number       object\n",
              "engine_size            int64\n",
              "fuel_system           object\n",
              "bore_ratio           float64\n",
              "stroke               float64\n",
              "compression_ratio    float64\n",
              "horse_power            int64\n",
              "peak_rpm               int32\n",
              "city_mpg               int64\n",
              "highway_mpg            int64\n",
              "price                 object\n",
              "car_company           object\n",
              "dtype: object"
            ]
          },
          "execution_count": 44,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df.dtypes"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "CtIGrLHigm9j",
        "outputId": "47c6fd44-7b2d-4544-e47d-303c98623365"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "door_number\n",
            "peak_rpm\n"
          ]
        }
      ],
      "source": [
        "for col in df.columns:\n",
        "    if(df[col].dtype == \"int32\"):\n",
        "        print(col)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Pd6J2ZiAgm9k"
      },
      "outputs": [],
      "source": [
        "for col in df.columns:\n",
        "    if(df[col].dtype == \"int32\"):\n",
        "        df[col] = df[col].astype(\"int64\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IuKQaXUqgm9l",
        "outputId": "93841aa2-c12f-409d-a64d-9eadd97a8944"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 205 entries, 0 to 204\n",
            "Data columns (total 26 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   car_id             205 non-null    int64  \n",
            " 1   symboling          205 non-null    int64  \n",
            " 2   fuel_type          205 non-null    object \n",
            " 3   aspiration         205 non-null    object \n",
            " 4   door_number        205 non-null    int64  \n",
            " 5   car_body           205 non-null    object \n",
            " 6   drive_wheel        205 non-null    object \n",
            " 7   engine_location    205 non-null    object \n",
            " 8   wheel_base         205 non-null    float64\n",
            " 9   car_length         205 non-null    float64\n",
            " 10  car_width          205 non-null    float64\n",
            " 11  car_height         205 non-null    float64\n",
            " 12  curb_weight        205 non-null    int64  \n",
            " 13  engine_type        205 non-null    object \n",
            " 14  cylinder_number    205 non-null    object \n",
            " 15  engine_size        205 non-null    int64  \n",
            " 16  fuel_system        205 non-null    object \n",
            " 17  bore_ratio         205 non-null    float64\n",
            " 18  stroke             205 non-null    float64\n",
            " 19  compression_ratio  205 non-null    float64\n",
            " 20  horse_power        205 non-null    int64  \n",
            " 21  peak_rpm           205 non-null    int64  \n",
            " 22  city_mpg           205 non-null    int64  \n",
            " 23  highway_mpg        205 non-null    int64  \n",
            " 24  price              205 non-null    object \n",
            " 25  car_company        205 non-null    object \n",
            "dtypes: float64(7), int64(9), object(10)\n",
            "memory usage: 41.8+ KB\n"
          ]
        }
      ],
      "source": [
        "df.info()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "p-zI_0Efgm9o",
        "outputId": "b3dd8782-f427-4ab0-e2a9-41cfe496a9e0"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>car_id</th>\n",
              "      <th>symboling</th>\n",
              "      <th>door_number</th>\n",
              "      <th>wheel_base</th>\n",
              "      <th>car_length</th>\n",
              "      <th>car_width</th>\n",
              "      <th>car_height</th>\n",
              "      <th>curb_weight</th>\n",
              "      <th>engine_size</th>\n",
              "      <th>bore_ratio</th>\n",
              "      <th>stroke</th>\n",
              "      <th>compression_ratio</th>\n",
              "      <th>horse_power</th>\n",
              "      <th>peak_rpm</th>\n",
              "      <th>city_mpg</th>\n",
              "      <th>highway_mpg</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>88.6</td>\n",
              "      <td>168.8</td>\n",
              "      <td>64.1</td>\n",
              "      <td>48.8</td>\n",
              "      <td>2548</td>\n",
              "      <td>130</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5000</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>88.6</td>\n",
              "      <td>168.8</td>\n",
              "      <td>64.1</td>\n",
              "      <td>48.8</td>\n",
              "      <td>2548</td>\n",
              "      <td>130</td>\n",
              "      <td>3.47</td>\n",
              "      <td>2.68</td>\n",
              "      <td>9.0</td>\n",
              "      <td>111</td>\n",
              "      <td>5000</td>\n",
              "      <td>21</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>94.5</td>\n",
              "      <td>171.2</td>\n",
              "      <td>65.5</td>\n",
              "      <td>52.4</td>\n",
              "      <td>2823</td>\n",
              "      <td>152</td>\n",
              "      <td>2.68</td>\n",
              "      <td>3.47</td>\n",
              "      <td>9.0</td>\n",
              "      <td>154</td>\n",
              "      <td>5000</td>\n",
              "      <td>19</td>\n",
              "      <td>26</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>4</td>\n",
              "      <td>99.8</td>\n",
              "      <td>176.6</td>\n",
              "      <td>66.2</td>\n",
              "      <td>54.3</td>\n",
              "      <td>2337</td>\n",
              "      <td>109</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>10.0</td>\n",
              "      <td>102</td>\n",
              "      <td>5500</td>\n",
              "      <td>24</td>\n",
              "      <td>30</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>2</td>\n",
              "      <td>4</td>\n",
              "      <td>99.4</td>\n",
              "      <td>176.6</td>\n",
              "      <td>66.4</td>\n",
              "      <td>54.3</td>\n",
              "      <td>2824</td>\n",
              "      <td>136</td>\n",
              "      <td>3.19</td>\n",
              "      <td>3.40</td>\n",
              "      <td>8.0</td>\n",
              "      <td>115</td>\n",
              "      <td>5500</td>\n",
              "      <td>18</td>\n",
              "      <td>22</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   car_id  symboling  door_number  wheel_base  car_length  car_width  \\\n",
              "0       1          3            2        88.6       168.8       64.1   \n",
              "1       2          3            2        88.6       168.8       64.1   \n",
              "2       3          1            2        94.5       171.2       65.5   \n",
              "3       4          2            4        99.8       176.6       66.2   \n",
              "4       5          2            4        99.4       176.6       66.4   \n",
              "\n",
              "   car_height  curb_weight  engine_size  bore_ratio  stroke  \\\n",
              "0        48.8         2548          130        3.47    2.68   \n",
              "1        48.8         2548          130        3.47    2.68   \n",
              "2        52.4         2823          152        2.68    3.47   \n",
              "3        54.3         2337          109        3.19    3.40   \n",
              "4        54.3         2824          136        3.19    3.40   \n",
              "\n",
              "   compression_ratio  horse_power  peak_rpm  city_mpg  highway_mpg  \n",
              "0                9.0          111      5000        21           27  \n",
              "1                9.0          111      5000        21           27  \n",
              "2                9.0          154      5000        19           26  \n",
              "3               10.0          102      5500        24           30  \n",
              "4                8.0          115      5500        18           22  "
            ]
          },
          "execution_count": 48,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "numerical_df = df.select_dtypes(include=['int64', 'float64'])\n",
        "\n",
        "numerical_df.head()"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Can you fix the Price Column? "
      ],
      "metadata": {
        "id": "KT0V28B7mp4C"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 53,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "9t3D5_brgm9o",
        "outputId": "871be8c7-a2c5-4350-ff78-2407654d7b72"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 205 entries, 0 to 204\n",
            "Data columns (total 26 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   car_id             205 non-null    int64  \n",
            " 1   symboling          205 non-null    int64  \n",
            " 2   fuel_type          205 non-null    object \n",
            " 3   aspiration         205 non-null    object \n",
            " 4   door_number        205 non-null    int64  \n",
            " 5   car_body           205 non-null    object \n",
            " 6   drive_wheel        205 non-null    object \n",
            " 7   engine_location    205 non-null    object \n",
            " 8   wheel_base         205 non-null    float64\n",
            " 9   car_length         205 non-null    float64\n",
            " 10  car_width          205 non-null    float64\n",
            " 11  car_height         205 non-null    float64\n",
            " 12  curb_weight        205 non-null    int64  \n",
            " 13  engine_type        205 non-null    object \n",
            " 14  cylinder_number    205 non-null    object \n",
            " 15  engine_size        205 non-null    int64  \n",
            " 16  fuel_system        205 non-null    object \n",
            " 17  bore_ratio         205 non-null    float64\n",
            " 18  stroke             205 non-null    float64\n",
            " 19  compression_ratio  205 non-null    float64\n",
            " 20  horse_power        205 non-null    int64  \n",
            " 21  peak_rpm           205 non-null    int64  \n",
            " 22  city_mpg           205 non-null    int64  \n",
            " 23  highway_mpg        205 non-null    int64  \n",
            " 24  price              205 non-null    object \n",
            " 25  car_company        205 non-null    object \n",
            "dtypes: float64(7), int64(9), object(10)\n",
            "memory usage: 41.8+ KB\n"
          ]
        }
      ],
      "source": [
        "df.info()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.5"
    },
    "colab": {
      "provenance": [],
      "collapsed_sections": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}